//
//  SeparatePigCell.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/14.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "SeparatePigCell.h"

@interface SeparatePigCell()

@end


@implementation SeparatePigCell

#pragma mark - lifecycle methods

- (void)setupUI
{
    [self addSubview:self.logo];
    [self addSubview:self.titleLab];
    [self addSubview:self.contentLab];
    [self addSubview:self.tipLab];
    [self addSubview:self.goingLab];

}

- (void)setupLayout
{
    {
        _logo.size = CGSizeMake(KScreenWidth - 30, 112);
        _logo.mj_x = 15;
        _logo.mj_y = 12;
    }
    
    {
        _titleLab.size = CGSizeMake(KScreenWidth - 30, 25);
        _titleLab.mj_x = 15;
        _titleLab.mj_y = _logo.bottom +12;
    }
    
    {
        
        _contentLab.frame = CGRectMake(0, 0, KScreenWidth - 30, 40);
       // [_contentLab sizeToFit];
        _contentLab.mj_x = 15;
        _contentLab.mj_y = _titleLab.bottom +12;
    }
    
    {
        _tipLab.size = CGSizeMake(100, 17);
        _tipLab.mj_x = 15;
        _tipLab.mj_y = _contentLab.bottom +17;
    }
    
    {
        _goingLab.size = CGSizeMake(100, 17);
        _goingLab.mj_x = KScreenWidth - _goingLab.width - 15;
        _goingLab.mj_y = _contentLab.bottom +17;
    }

}


#pragma mark - setter methods

- (void)setItem:(ShopSeparatePlanItem *)item{
    
    _titleLab.text = item.divisionPlanName;
    [_logo sd_setImageWithURL:[NSURL URLWithString:item.imgName] placeholderImage:[UIImage imageNamed:@"placeholder_large"]];
    
    NSString * htmlString = item.content;
    NSAttributedString *attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
    _contentLab.attributedText = attrStr;
    
    _tipLab.text = [NSString stringWithFormat:@"%@人选择", item.selectNum];
    
    [self setupLayout];

}

#pragma mark - getter methods

- (UIImageView *)logo
{
    if (!_logo) {
        _logo = [UIImageView new];
        _logo.image = [UIImage imageNamed:@"placeholder_large"];
    }
    return _logo;
}


- (UILabel *)titleLab{
    
    if (!_titleLab) {
        _titleLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0x262626) font:mMediumFont(18) textAliment:0];
    }
    return _titleLab;
}


- (UILabel *)contentLab{
    
    if (!_contentLab) {
        _contentLab = [UILabel makeLabelWithText:@"将整猪屠宰，精选其中优质肉品做礼盒包装，剩余次品走渠道外销。将整猪屠宰，精选其中优质肉品做礼盒…" textColor:UIColorFromRGB(0x666666) font:mFont(14) textAliment:0];
        _contentLab.numberOfLines = 0;
    }
    return _contentLab;
}


- (UILabel *)tipLab{
    
    if (!_tipLab) {
        _tipLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0xA1A1A1) font:mFont(12) textAliment:0];
    }
    return _tipLab;
}


- (UILabel *)goingLab{
    
    if (!_goingLab) {
        _goingLab = [UILabel new];
        _goingLab.textAlignment = NSTextAlignmentRight;
        
        NSMutableAttributedString *puStr = [@"查看详情" createAttributingByIcon:nil downIndexImage:@"meat_cart_enter" textColor:UIColorFromRGB(0x333333) font:mFont(14)];
        [_goingLab setAttributedText:puStr];
        
    }
    return _goingLab;
}


@end
